﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Cluster.LiveJournalLib;

namespace Cluster.JeJePoster
{
    public partial class FriendSelectForm : Form
    {
        public FriendSelectForm(IEnumerable<FriendInfo> friends)
        {
            Cursor.Current = Cursors.WaitCursor;
            InitializeComponent();
            foreach(var friend in friends)
            {
                var item = new ListViewItem(friend.userName);
                switch (friend.friendType)
                {
                    case FriendType.Normal: item.ImageIndex = 0; break;
                    case FriendType.Community: item.ImageIndex = 1; break;
                }
                item.ForeColor = friend.foregroundColor;
                item.BackColor = friend.backgroundColor;
                listViewFriends.Items.Add(item);
            }
            Cursor.Current = Cursors.Default;
        }

        public string GetSelectedFriends()
        {
            var friends = new StringBuilder();
            foreach(ListViewItem item in listViewFriends.Items)
            {
                if (item.Checked)
                {
                    if (friends.Length > 0) friends.Append(", ");
                    switch (item.ImageIndex)
                    {
                        case 0:
                            friends.Append("<lj user=\"" + item.Text + "\">");
                            break;
                        case 1:
                            friends.Append("<lj comm=\"" + item.Text + "\">");
                            break;
                    }
                }
            }
            return friends.ToString();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void menuItemCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}